package com.sias.swagger.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sias.swagger.common.BaseResponse;
import com.sias.swagger.common.ErrorCode;
import com.sias.swagger.common.ResultUtils;
import com.sias.swagger.exception.BusinessException;
import com.sias.swagger.mapper.UserMapper;
import com.sias.swagger.model.domain.User;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 吴文杰
 * @version 1.0
 * @createTime 2023-05-19 10:54:13
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户管理")
public class UserController {

  @Resource
  UserMapper userMapper;

  @GetMapping("/getUserById/{id}")
  public BaseResponse<User> getUserById(@PathVariable("id") long id) {
    if (id<1){
      throw new BusinessException(ErrorCode.PARAMS_ERROR);
    }
    if(id>10){
      int a = 1/0;
    }
    QueryWrapper<User> wrapper = new QueryWrapper<>();
    wrapper.eq("id",id);
    User user = userMapper.selectOne(wrapper);
    return ResultUtils.success(user);
  }

}
